import errorImage from '@/assets/image/error.png'
/**
 * 全局图片异常加载
 * @param fallback
 */
export function setupImgError(fallback = errorImage) {
    window.addEventListener('error', (e) => {
            const target = e.target as HTMLElement
            if (target && target.tagName === 'IMG') {
                const img = target as HTMLImageElement
                if (!img.src.includes(fallback)) {
                    img.src = fallback
                }
            }
        },
        true // 捕获
    )
}
